package com.czl.base.base

import com.czl.base.R
import com.czl.base.BR
import com.czl.base.adapter.ViewPagerFmAdapter
import com.czl.base.databinding.FragmentBaseTabBinding
import me.yokeyword.fragmentation.SupportFragment

abstract class BaseTabFragment<V : FragmentBaseTabBinding, VM: BaseTabViewModel> : BaseFragment<V, VM>() {
    override fun initContentView(): Int {
        return R.layout.fragment_base_tab
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }

    override fun initData() {
        hiddenBottomShadow()
        binding.viewPager.apply {
            adapter = ViewPagerFmAdapter(childFragmentManager, lifecycle, fragments())
        }
    }

    abstract fun fragments(): List<SupportFragment>

    override fun initViewObservable() {
        viewModel.uc.tabChangeLiveEvent.observe(this, {
            binding.viewPager.setCurrentItem(it, false)
        })
        viewModel.uc.pageChangeLiveEvent.observe(this, {
            binding.tabLayout.currentTab = it
        })
    }
}